package com.wangzh.network.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class SendMessge {
    public static void main(String[] args) throws IOException {
        //        发送数据
        /**
         * 1.创建对象
         * 2.组装数据
         * 3.发送数据
         * 4.释放资源
         */
        DatagramSocket ds = new DatagramSocket();

        InetAddress address = InetAddress.getByName("127.0.0.1");

        Scanner scanner = new Scanner(System.in);
        while (true) {
            String s = scanner.nextLine();
            if (s.equals("886")) {
                break;
            }
            byte[] bytes = s.getBytes();

            DatagramPacket dp = new DatagramPacket(bytes, bytes.length,address,10086);

            ds.send(dp);
        }

        ds.close();
    }
}
